<?php

class TextsController extends AppController {

    var $name = 'Texts';

    function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->userModel = 'admin';
        $this->Auth->fields = array('username' => 'user', 'password' => 'mot-passe');
        $this->Auth->allow('obtenir_text');
        $this->Auth->loginAction = array('controller' => 'admins', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
        $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
    }

    function lister_sections(){
       $this->set( 'texts',$this->Text->find('all'));
    }

    function modifier_section($id){
        $this->Text->id = $id;
	if (empty($this->data)) {
		$this->data = $this->Text->read();
	} else {
		if ($this->Text->save($this->data)) {
			$this->Session->setFlash('La modification a été faite.');
			$this->redirect(array('action' => 'lister_sections'));
		}
	}

    }

  

    function obtenir_text($section,$lang){
        
        $text=$this->Text->findBySection($section);
        
        if($lang=='fre'){
            return $text['Text']['text_fre'];
        }else if($lang=='eng'){
            return $text['Text']['text_eng'];
        }else if($lang=='esp'){
            return $text['Text']['text_esp'];
        }else{
            return 'Pas de texte';
        }
    }

}

?>